using System;

namespace Quiki.ExpressionParsers
{
    public class ParagraphExpressionParser : IWikiLineExpressionParser
    {
        public bool Process(string wikiText, WikiTextElement parentElement)
        {
            if (parentElement.ChildElements.Count > 0)
            {
                WikiTextElement previousElement = parentElement.ChildElements[
                    parentElement.ChildElements.Count - 1];
                switch (previousElement.ElementType)
                {
                    case WikiTextElementType.ListDefinition:
                    case WikiTextElementType.ListOrdered:
                    case WikiTextElementType.ListUnordered:
                    case WikiTextElementType.Paragraph:
                        previousElement.Text += ' ' + wikiText.Trim();
                        return true;
                }
            }

            WikiTextElement element = new WikiTextElement(WikiTextElementType.Paragraph, 1, wikiText);
            parentElement.ChildElements.Add(element);

            return true;
        }
    }
}